package com.augurit.common.workdayholiday.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.common.entity.WhRegularWorkTime;
import com.augurit.common.workdayholiday.model.Week;
import com.augurit.common.workdayholiday.web.form.WhRegularWorkTimeForm;

public class WhRegularWorkTimeConvertor {
	
	public static WhRegularWorkTimeForm convertVoToForm(WhRegularWorkTime entity){
		if(entity != null) {
			WhRegularWorkTimeForm form = new WhRegularWorkTimeForm();
			form.setId(entity.getId());
			form.setWorkday(entity.getWorkday());
			form.setPmStartHour(entity.getPmStartHour());
			form.setAmStartHour(entity.getAmStartHour());
			form.setAmStartMinute(entity.getAmStartMinute());
			form.setAmEndHour(entity.getAmEndHour());
			form.setAmEndMinute(entity.getAmEndMinute());
			form.setPmStartMinute(entity.getPmStartMinute());
			form.setPmEndHour(entity.getPmEndHour());
			form.setPmEndMinute(entity.getPmEndMinute());
			
			form.setAmStartTime(entity.getAmStartTime());
			form.setAmEndTime(entity.getAmEndTime());
			form.setPmStartTime(entity.getPmStartTime());
			form.setPmEndTime(entity.getPmEndTime());
			
			form.setMemo(entity.getMemo());
			form.setWorkdayDesc(Week.get(Integer.valueOf(entity.getWorkday())).getDescription());
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(WhRegularWorkTimeForm form, WhRegularWorkTime entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			if(form.getWorkday() != null && form.getWorkday().trim().length() > 0)
				entity.setWorkday(form.getWorkday().trim());
			entity.setPmStartHour(form.getPmStartHour());
			entity.setAmStartHour(form.getAmStartHour());
			entity.setAmStartMinute(form.getAmStartMinute());
			entity.setAmEndHour(form.getAmEndHour());
			entity.setAmEndMinute(form.getAmEndMinute());
			entity.setPmStartMinute(form.getPmStartMinute());
			entity.setPmEndHour(form.getPmEndHour());
			entity.setPmEndMinute(form.getPmEndMinute());
			
			entity.setAmStartTime(form.getAmStartTime());
			entity.setAmEndTime(form.getAmEndTime());
			entity.setPmStartTime(form.getPmStartTime());
			entity.setPmEndTime(form.getPmEndTime());
			if(form.getMemo() != null && form.getMemo().trim().length() > 0)
				entity.setMemo(form.getMemo().trim());
		}
	}
	
	public static List<WhRegularWorkTimeForm> convertVoListToFormList(List<WhRegularWorkTime> whWorkhoursList) {
		if(whWorkhoursList != null && whWorkhoursList.size() > 0) {
			List<WhRegularWorkTimeForm> whWorkhoursFormList = new ArrayList();
			for(int i=0; i<whWorkhoursList.size(); i++) {
				whWorkhoursFormList.add(convertVoToForm(whWorkhoursList.get(i)));
			}
			return whWorkhoursFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<WhRegularWorkTime> whWorkhoursList) {
		if(whWorkhoursList != null && whWorkhoursList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<whWorkhoursList.size(); i++) {
				WhRegularWorkTime entity = whWorkhoursList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("workday", entity.getWorkday());
				map.put("pmStartHour", entity.getPmStartHour() == null ? "" : entity.getPmStartHour().toString());
				map.put("amStartHour", entity.getAmStartHour() == null ? "" : entity.getAmStartHour().toString());
				map.put("amStartMinute", entity.getAmStartMinute() == null ? "" : entity.getAmStartMinute().toString());
				map.put("amEndHours", entity.getAmEndHour() == null ? "" : entity.getAmEndHour().toString());
				map.put("amEndMinute", entity.getAmEndMinute() == null ? "" : entity.getAmEndMinute().toString());
				map.put("pmStartMinute", entity.getPmStartMinute() == null ? "" : entity.getPmStartMinute().toString());
				map.put("pmEndHour", entity.getPmEndHour() == null ? "" : entity.getPmEndHour().toString());
				map.put("pmEndMinute", entity.getPmEndMinute() == null ? "" : entity.getPmEndMinute().toString());
				map.put("memo", entity.getMemo());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<WhRegularWorkTime> convertFormListToVoList(List<WhRegularWorkTimeForm> whWorkhoursFormList) {
		if(whWorkhoursFormList != null && whWorkhoursFormList.size() > 0) {
			List<WhRegularWorkTime> whWorkhoursList = new ArrayList();
			for(int i=0; i<whWorkhoursFormList.size(); i++) {
				WhRegularWorkTime whWorkhours = new WhRegularWorkTime();
				convertFormToVo(whWorkhoursFormList.get(i), whWorkhours);
				whWorkhoursList.add(whWorkhours);
			}
			return whWorkhoursList;
		}
		return null;
	}
}